angular.module('homeMod',['HDmod'])
.controller('homeCtrl',['$scope','$http','$timeout','cart','total',function($scope,$http,$timeout,cart,total){

		$http({
			url: 'http://h5.yztctech.net/api/axf/apihome.php',
			method: "get"
		}).success(function(res){
			$scope.bannerList = res.data.slide;
			$scope.menuList = res.data.menu;
			$timeout(function() {
				swiper();
			}, 200);
		})
		function swiper(){
			var swiper = new Swiper('.swiper-container',{
				pagination:'.swiper-pagination',
				paginationClickable: true,
				loop:true,
				effect: 'slide',
				autoplay:2000,
				autoplayDisableOnInteraction:false
			});
		}
		$scope.text1 = '';
		$http({
			url: 'http://h5.yztctech.net/api/axf/apicategory.php?',
			method: "get",
			params: {
				'category': '优选水果'
			}
		}).success(function(res){
			$scope.fruitList = res.data;
			$scope.text1 = '优选水果';
		})
		$scope.text2 = '';
		$http({
			url: 'http://h5.yztctech.net/api/axf/apicategory.php?',
			method: "get",
			params: {
				'category': '牛奶面包'
			}
		}).success(function(res){
			$scope.milkList = res.data;
			$scope.text2 = '牛奶面包';
		})
		$scope.text3 = '';
		$http({
			url: 'http://h5.yztctech.net/api/axf/apicategory.php?',
			method: "get",
			params: {
				'category': '天天特价'
			}
		}).success(function(res){
			$scope.todayList = res.data;
			$scope.text3 = '天天特价';
		})
		$scope.add1 = function(i){
			if (!i.num) {
				i.num = 1;
			} else{
				i.num++
			}
			cart.addFun(i,$scope.text1);
			total.fun();
		}
		$scope.add2 = function(i){
			if (!i.num) {
				i.num = 1;
			} else{
				i.num++
			}
			cart.addFun(i,$scope.text2);
			total.fun();
		}

		$scope.add3 = function(i){
			if (!i.num) {
				i.num = 1;
			} else{
				i.num++
			}
			cart.addFun(i,$scope.text3);
			total.fun();
		}


}])



